package com.rtx.wms.std.sku.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.wms.std.sku.bean.po.AltSku;
import com.rtx.wms.std.sku.mapper.AltskuMapper;
import com.rtx.wms.std.sku.service.AltSkuService;

@Service
public class AltSkuServiceImpl extends ServiceImpl<AltskuMapper,AltSku> implements AltSkuService{

	@DataSourceAnnotation
	@Override
	public void addAndUpdAltSku(String datasourcekey, AltSku sku) {
		LambdaQueryWrapper<AltSku> lqw = Wrappers.lambdaQuery();
		lqw.eq(AltSku::getSku, sku.getSku());
		lqw.eq(AltSku::getStorerkey, sku.getStorerkey());
		boolean exists = baseMapper.exists(lqw);
		if(exists) {
			LambdaUpdateWrapper<AltSku> upd = Wrappers.lambdaUpdate();
			upd.eq(AltSku::getSku, sku.getSku());
			upd.eq(AltSku::getStorerkey, sku.getStorerkey());
			upd.set(AltSku::getAltsku, sku.getAltsku());
			upd.set(AltSku::getEditdate, sku.getEditdate());
			upd.set(AltSku::getEditwho, sku.getEditwho());
			baseMapper.update(null, upd);
		}else {
			sku.setSerialkey(null);
			baseMapper.insert(sku);
		}
	}

}
